package com.shanzmoo.merchant.manage.api.web.open;

import com.shanzmoo.base.bean.SHttpResponse;
import com.shanzmoo.core.domain.OssCallbackVO;
import com.shanzmoo.core.domain.OssPolicyVO;
import com.shanzmoo.core.manager.base.OssManager;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * Oss相关操作接口
 * @author Gzhao
 * @date 2020/12/1
 */
@Slf4j
@Api(tags = "系统管理-Oss")
@RestController
public class OssController {

    @Autowired
    private OssManager ossManager;

    @ApiOperation(value = "状态检查")
    @GetMapping(value = "/open/status")
    public String stautsCheck() {
        return "200";
    }

    @ApiOperation(value = "oss上传签名生成")
    @PostMapping(value = "/api/oss/policy")
    public SHttpResponse<OssPolicyVO> obtainPolicy() {
        return SHttpResponse.ok(ossManager.policy());
    }

    @ApiOperation(value = "oss上传成功回调")
    @PostMapping(value = "/open/oss/callback")
    public SHttpResponse<OssCallbackVO> callback(HttpServletRequest request) {
        log.info("oss callback回调成功......");
        return SHttpResponse.ok(ossManager.callback(request));
    }

}
